<!--
 * @Author: mikeShn
 * @Date: 2022-04-11 10:11:06
 * @LastEditTime: 2022-04-12 14:17:40
 * @FilePath: \Long-term-vision-of-the-times-PC\src\views\components\z-form\z-number\index.vue
 * @Description: 文件说明
-->
<template>
  <el-input
    v-model="inputVal"
    :disabled="isReadonly"
    @input="change"
    :placeholder="isReadonly ? '' : `请输入${config.name}`"
    clearable
    :maxlength="config.maxlength ? config.maxlength : ''"
  >
  </el-input>
</template>
<script>
export default {
  props: {
    isReadonly: {
      type: Boolean,
      default: false,
    },
    formData: Object,
    config: {
      type: Object,
      default: () => Object.create(null),
    },
  },
  data() {
    return {
      inputVal: null,
    };
  },
  computed: {
    curVal() {
      return this.formData[this.config.prop] || "";
    },
  },
  watch: {
    curVal: {
      immediate: true,
      deep: true,
      handler(val) {
        this.inputVal = val;
      },
    },
  },
  methods: {
    change(val) {
      this.inputVal = val;
      this.formData[this.config.prop] = val;
      this.$emit("update:formData", this.formData);
      this.$emit("change");
    },
  },
  mounted() {},
};
</script>
<style lang="scss" scoped></style>
